package com.szcinda.controller;

import com.szcinda.controller.configuration.UserLoginToken;
import com.szcinda.repository.TransportType;
import com.szcinda.service.dto.transportType.TransportTypeCreateDto;
import com.szcinda.service.dto.transportType.TransportTypeQueryDto;
import com.szcinda.service.dto.transportType.TransportTypeService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("transportType")
public class TransportTypeController {

    private final TransportTypeService transportTypeService;

    public TransportTypeController(TransportTypeService transportTypeService) {
        this.transportTypeService = transportTypeService;
    }


    @UserLoginToken
    @PostMapping("create")
    @OperationLogAnnotation(operDesc = "新增运输类型")
    public Result<String> create(@RequestBody TransportTypeCreateDto createDto) {
        transportTypeService.add(createDto);
        return Result.success();
    }

    @GetMapping("del/{id}/{userId}")
    @OperationLogAnnotation(operDesc = "删除运输类型")
    public Result<String> del(@PathVariable String id, @PathVariable String userId) {
        transportTypeService.delete(id, userId);
        return Result.success();
    }

    @UserLoginToken
    @PostMapping("getAll")
    public Result<List<TransportType>> query(@RequestBody TransportTypeQueryDto queryDto) {
        return Result.success(transportTypeService.findAll(queryDto));
    }

    @GetMapping("all")
    public Result<List<TransportType>> all() {
        return Result.success(transportTypeService.getAll());
    }
}
